package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Message;
import cn.wolfcode.trip.base.mapper.MessageMapper;
import cn.wolfcode.trip.base.query.MessageQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IMessageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

@Service
public class MessageServiceImpl implements IMessageService {

    @Autowired
    private MessageMapper messageMapper;

    @Override
    public PageInfo query(MessageQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<Message> list = messageMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public int queryNumber(Long userId, Integer state) {
        return messageMapper.selectForCountByState(userId, state);
    }

    @Override
    public void save(Message msg) {
        messageMapper.insert(msg);
    }
}
